<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取系统的高精度时间</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.highlight-string.html">« highlight_string</a></li>
      <li style="float: right;"><a href="function.ignore-user-abort.html">ignore_user_abort »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.misc.html">杂项 函数</a></li>
    <li>获取系统的高精度时间</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.hrtime" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">hrtime</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.3.0, PHP 8)</p><p class="refpurpose"><span class="refname">hrtime</span> &mdash; <span class="dc-title">获取系统的高精度时间</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.hrtime-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>hrtime</strong></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$as_number</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type">int</span>|<span class="type">float</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="simpara">
   从任意时间点开始统计，返回系统的高精度时间（high resolution time）。
   获取的时间戳为单调时间，无法被用户调整。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.hrtime-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">as_number</code></dt>

     <dd>

      <p class="para">
       以 <span class="type">array</span> 还是数字返回高精度时间。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.hrtime-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   参数 <code class="parameter">as_number</code> 为 false 时，返回的整型数组格式为
   [seconds, nanoseconds]。否则会以 <span class="type">int</span> （64 位平台）或
   <span class="type">float</span> （32 位平台）返回奈秒（nanoseconds）。失败时返回 <strong><code>false</code></strong>。 
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.hrtime-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3453">
    <p><strong>示例 #1 <span class="function"><strong>hrtime()</strong></span> 的用法</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">hrtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">hrtime</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
10444739687370679
Array
(
    [0] =&gt; 10444739
    [1] =&gt; 687464812
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.hrtime-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><a href="book.hrtime.html" class="link">高精度记时</a>扩展</li>
   <li class="member"><span class="function"><a href="function.microtime.html" class="function" rel="rdfs-seeAlso">microtime()</a> - 返回当前 Unix 时间戳和微秒数</span></li>
  </ul>
 </div>


</div></div></div></body></html>